<template>
  <div class="child">
    我是组件二号
    {{ val }}
    <input :value="val" @input="changeVal" type="text" />
  </div>
</template>

<script>
import { mapState } from 'vuex' // 在vuex中导入mapState辅助函数
export default {
  data () {
    return {}
  },
  methods: {
    changeVal (e) {
      this.$store.commit('changeVal', e.target.value.trim())
    }
  },
  computed: {
    ...mapState(['val'])
  },
  beforeMount () {
    // console.log(this.val)
  }
}
</script>

<style></style>
